//
// Created by uts on 10/21/21.
//
#include "frame-queue.h"

FrameQueue::FrameQueue()
        :nb_frame(0)
{
}

FrameQueue::~FrameQueue() {}

bool FrameQueue::put(DataBlock *frame) {
    std::unique_lock<std::mutex> lock(mutex);
    if (nb_frame < FrameQueueSize){
        queue.push(frame);
        nb_frame++;
    }
    if (nb_frame >= FrameQueueSize) {
        cv.wait(lock);
    }
    cv.wait(lock);
    return true;
}

DataBlock* FrameQueue::get() {
    DataBlock* frame = nullptr;
    std::unique_lock<std::mutex> lock(mutex);
    if (!queue.empty()) {
        frame = queue.front();
//        frame = frameInfo;
        queue.pop();
        nb_frame--;
    }
    cv.notify_all();
    return frame;
}



